package com.marketing.tenant.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.validation.constraints.DecimalMin;
import java.time.LocalDateTime;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Objects;

/**
 * 租户订阅实体类
 * 对应数据库表：saas_tenant_subscription
 */
@TableName("saas_tenant_subscription")
@Schema(name = "TenantSubscription", description = "租户订阅信息")
public class TenantSubscription {

    /**
     * 订阅ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    @Schema(description = "订阅ID", example = "1")
    private Long id;

    /**
     * 租户ID
     */
    @NotNull(message = "租户ID不能为空")
    @TableField("tenant_id")
    private Long tenantId;

    /**
     * 计划ID
     */
    @NotNull(message = "计划ID不能为空")
    @TableField("plan_id")
    private Long planId;

    /**
     * 订阅开始日期
     */
    @NotNull(message = "订阅开始日期不能为空")
    @TableField("start_date")
    private LocalDate startDate;

    /**
     * 订阅结束日期
     */
    @NotNull(message = "订阅结束日期不能为空")
    @TableField("end_date")
    private LocalDate endDate;

    /**
     * 订阅状态：ACTIVE-生效，EXPIRED-过期，SUSPENDED-暂停，CANCELLED-取消
     */
    @Size(max = 20, message = "订阅状态长度不能超过20个字符")
    private String status = "ACTIVE";

    /**
     * 是否自动续费：1-是，0-否
     */
    @TableField("auto_renew")
    private Integer autoRenew = 0;

    /**
     * 支付状态：PENDING-待支付，PAID-已支付，FAILED-支付失败
     */
    @Size(max = 20, message = "支付状态长度不能超过20个字符")
    @TableField("payment_status")
    private String paymentStatus = "PENDING";

    /**
     * 订阅总金额
     */
    @DecimalMin(value = "0.00", message = "订阅总金额不能为负数")
    @TableField("total_amount")
    private BigDecimal totalAmount = BigDecimal.ZERO;

    /**
     * 已支付金额
     */
    @DecimalMin(value = "0.00", message = "已支付金额不能为负数")
    @TableField("paid_amount")
    private BigDecimal paidAmount = BigDecimal.ZERO;

    /**
     * 备注
     */
    private String notes;

    /**
     * 软删除标记：0-未删除，1-已删除
     */
    @TableLogic
    private Integer deleted = 0;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    // 关联对象
    /**
     * 租户信息（关联查询时使用）
     */
    @TableField(exist = false)
    private Tenant tenant;

    /**
     * 订阅计划信息（关联查询时使用）
     */
    @TableField(exist = false)
    private SubscriptionPlan plan;
    
    // 手动添加getter和setter方法
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getTenantId() {
        return tenantId;
    }
    
    public void setTenantId(Long tenantId) {
        this.tenantId = tenantId;
    }
    
    public Long getPlanId() {
        return planId;
    }
    
    public void setPlanId(Long planId) {
        this.planId = planId;
    }
    
    public LocalDate getStartDate() {
        return startDate;
    }
    
    public void setStartDate(LocalDate startDate) {
        this.startDate = startDate;
    }
    
    public LocalDate getEndDate() {
        return endDate;
    }
    
    public void setEndDate(LocalDate endDate) {
        this.endDate = endDate;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public Integer getAutoRenew() {
        return autoRenew;
    }
    
    public void setAutoRenew(Integer autoRenew) {
        this.autoRenew = autoRenew;
    }
    
    public String getPaymentStatus() {
        return paymentStatus;
    }
    
    public void setPaymentStatus(String paymentStatus) {
        this.paymentStatus = paymentStatus;
    }
    
    public BigDecimal getTotalAmount() {
        return totalAmount;
    }
    
    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }
    
    public BigDecimal getPaidAmount() {
        return paidAmount;
    }
    
    public void setPaidAmount(BigDecimal paidAmount) {
        this.paidAmount = paidAmount;
    }
    
    public String getNotes() {
        return notes;
    }
    
    public void setNotes(String notes) {
        this.notes = notes;
    }
    
    public Integer getDeleted() {
        return deleted;
    }
    
    public void setDeleted(Integer deleted) {
        this.deleted = deleted;
    }
    
    public LocalDateTime getCreateTime() {
        return createTime;
    }
    
    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
    
    public LocalDateTime getUpdateTime() {
        return updateTime;
    }
    
    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }
    
    public Tenant getTenant() {
        return tenant;
    }
    
    public void setTenant(Tenant tenant) {
        this.tenant = tenant;
    }
    
    public SubscriptionPlan getPlan() {
        return plan;
    }
    
    public void setPlan(SubscriptionPlan plan) {
        this.plan = plan;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TenantSubscription that = (TenantSubscription) o;
        return Objects.equals(id, that.id) &&
                Objects.equals(tenantId, that.tenantId) &&
                Objects.equals(planId, that.planId) &&
                Objects.equals(startDate, that.startDate) &&
                Objects.equals(endDate, that.endDate) &&
                Objects.equals(status, that.status) &&
                Objects.equals(autoRenew, that.autoRenew) &&
                Objects.equals(paymentStatus, that.paymentStatus) &&
                Objects.equals(totalAmount, that.totalAmount) &&
                Objects.equals(paidAmount, that.paidAmount) &&
                Objects.equals(notes, that.notes) &&
                Objects.equals(deleted, that.deleted) &&
                Objects.equals(createTime, that.createTime) &&
                Objects.equals(updateTime, that.updateTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, tenantId, planId, startDate, endDate, status, autoRenew, paymentStatus, totalAmount, paidAmount, notes, deleted, createTime, updateTime);
    }

    @Override
    public String toString() {
        return "TenantSubscription{" +
                "id=" + id +
                ", tenantId=" + tenantId +
                ", planId=" + planId +
                ", startDate=" + startDate +
                ", endDate=" + endDate +
                ", status='" + status + '\'' +
                ", autoRenew=" + autoRenew +
                ", paymentStatus='" + paymentStatus + '\'' +
                ", totalAmount=" + totalAmount +
                ", paidAmount=" + paidAmount +
                ", notes='" + notes + '\'' +
                ", deleted=" + deleted +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}